package cn.xp.web;

import cn.xp.domain.Device;
import cn.xp.domain.Floor;
import cn.xp.dto.DeviceDto;
import cn.xp.dto.DeviceTypeDto;
import cn.xp.dto.FloorDto;
import cn.xp.service.IDeviceService;
import cn.xp.util.JSONResult;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/device")
public class DeviceController {

    @Autowired
    private IDeviceService deviceService;
    @GetMapping("/{id}")
    public Device findOne(@PathVariable("id") Long id){
       return deviceService.findOne(id);
    }

    @GetMapping("/build/{id}")
    public List<DeviceDto> getDeviceDto(@PathVariable("id") Long id){
       return deviceService.getDeviceDto(id);
    }

    @GetMapping("/device")
    public List<Device> findAll(){
        return deviceService.findAll();
    }

    @PostMapping("/add")
    public JSONResult<Device> add(@RequestBody Device device){
        return deviceService.add(device);
    }

    /**
     * 根据设备id查询设备信息
     * @param id
     * @return
     */
//    localhost:8080/api/device/getDeviceInfoById?id=
    @GetMapping("/getDeviceInfoById/{id}")
    public JSONResult<DeviceDto>getDeviceInfoById(@PathVariable("id") Long id){
        return deviceService.getDeviceInfoById(id);
    }


    @GetMapping("/deviceType/{id}")
    public List<DeviceTypeDto>DeviceType(@PathVariable("id") Long id){
        return deviceService.DeviceType(id);
    }

    @GetMapping("/Type/{id}")
    public List<DeviceTypeDto> TypeList(@PathVariable("id") Long id){
        return deviceService.TypeList(id);
    }



}
